#!/usr/bin/env python
# -*- coding:utf8 -*-
from core import src
from interface import admin_interface

# 添加用户
def add_user():
    src.register()


# 修改额度
def change_balance():
    while 1:
        # 1.输入需要修改的用户额度
        change_user = input("请输入需要修改额度的用户：").strip()

        # 2.修改的用户额度
        money = input("请输入需要修改的额度：").strip()
        if not money.isdecimal():
            continue

        # 3.调用修改额度接口
        flag, msg = admin_interface.changer_balance_interface(
            change_user, money
        )
        if flag:
            print(msg)
            break
        else:
            print(msg)


# 冻结账户
def lock_user():
    while 1:
        # 1.输入需要冻结的用户
        change_user = input("请输入需要冻结的用户：").strip()

        flag, msg = admin_interface.lock_user_interface(
            change_user
        )
        if flag:
            print(msg)
            break
        else:
            print(msg)


# 管理员功能字典
admin_fun = {
    '1': add_user,
    '2': change_balance,
    '3': lock_user,
}


def admin_run():
    while 1:
        print("""
            1.添加用户
            2.修改额度
            3.冻结账户
        """)
        choice = input("请输入功能编号：").strip()
        if choice not in admin_fun:
            print("请输入正确的编号")
            continue
        admin_fun.get(choice)()
